﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_queryUser : System.Web.UI.Page
{
    db_users user = new db_users();
    DataSet ds;
    protected void Page_Load(object sender, EventArgs e)
    {
        Server.Execute("../inc/checkPurview.aspx");  // 此处用户权限验证
        if (!IsPostBack)
        {
            tb_userID.Text = Request.QueryString["userId"];
            tb_name.Text = Request.QueryString["userName"];
            tb_email.Text = Request.QueryString["email"];
            ddl_status.SelectedValue = Request.QueryString["status"];
            btn_search_Click(sender, e);
        }

       
        
    }

    protected void btn_search_Click(object sender, EventArgs e)
    {
        String userID = tb_userID.Text.Trim();
        String userName = tb_name.Text.Trim();
        String email = tb_email.Text.Trim();
        String status = ddl_status.SelectedValue;

        ds = user.selectUser_search(userID, userName, email, status);

        firstPage.NavigateUrl = null;
        prePage.NavigateUrl = null;
        nextPage.NavigateUrl = null;
        endPage.NavigateUrl = null;


        int CurPage;
        if (sender.GetType().Equals(new Button().GetType()))
        {
            CurPage = 1;
        }
        else
        {
            if (Request.QueryString["Page"] != null && Convert.ToInt32(Request.QueryString["Page"]) > 0)
                CurPage = Convert.ToInt32(Request.QueryString["Page"]);
            else
                CurPage = 1;
        }
        PagedDataSource ps = new PagedDataSource();
        ps.DataSource = ds.Tables[0].DefaultView;
        ps.AllowPaging = true;
        //每个页面显示的条数
        ps.PageSize = 10;
        onePage.Text = ps.PageSize.ToString();
        //求数据的总数
        allMsg.Text = ps.DataSourceCount.ToString();
        ps.CurrentPageIndex = CurPage - 1;
        //求总页
        allPages.Text = ps.PageCount.ToString();
        nowPage.Text = CurPage.ToString();
        //将数据源与控件绑定
        userList.DataSource = ps;
        userList.DataBind();

        //上一页
        if (!ps.IsFirstPage)
        {
            firstPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1&userId=" + userID + "&userName=" + userName + "&email=" + email + "&status=" + status;
            prePage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1) + "&userId=" + userID + "&userName=" + userName + "&email=" + email + "&status=" + status;
        }
        //下一页
        if (!ps.IsLastPage)
        {
            nextPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) + "&userId=" + userID + "&userName=" + userName + "&email=" + email + "&status=" + status;
            endPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(ps.PageCount) + "&userId=" + userID + "&userName=" + userName + "&email=" + email + "&status=" + status;
        }
        //分页 结束 -------
    }

    
    
}